package cn.changeforyou.web.dao.mybatis.ext.extBuilder.writer;

/**
 * @author zhyu
 * @version 1.0
 * @date 2022/3/10 20:08
 */
public class SqlBuilder {
    private StringBuilder sb;

    private String beforeWords;

    public SqlBuilder() {
        this.sb = new StringBuilder();
    }

    public SqlBuilder append(String str) {
        boolean append = true;
        String trim = str.trim();
        if ("and".equals(trim) || "or".equals(trim)) {
            if (this.beforeWords.equals("(")) {
                append = false;
            }
        }
        if (append) {
            this.sb.append(str);
            this.beforeWords = trim;
        }
        return this;
    }

    public char deleteCharAt(int index) {
        return this.sb.charAt(index);
    }

    public int length() {
        return sb.length();
    }

    public String toString() {
        return sb.toString();
    }
}
